package com.wgchao.amc.mapstruct.mapper.expand;

import com.wgchao.amc.entity.base.SysBaseFunc;
import com.wgchao.amc.entity.base.SysBaseMenu;
import com.wgchao.amc.mapstruct.DTOMapper;
import com.wgchao.amc.mapstruct.dto.SysBaseMenuDTO;
import com.wgchao.amc.mapstruct.mapper.SysBaseFuncMapper;
import com.wgchao.amc.mapstruct.mapper.SysBaseMenuMapper;
import com.wgchao.amc.repository.base.SysBaseFuncRepository;
import com.wgchao.amc.repository.base.SysBaseMenuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @作者：wgchao
 * @时间：22:05 2019/10/29 0029
 * @用途：
 **/
@Component
public class SysBaseMenuMapperExpand implements DTOMapper<SysBaseMenu, SysBaseMenuDTO> {
    @Autowired
    private SysBaseMenuMapper menuMapper;
    @Autowired
    private SysBaseMenuRepository menuRepository;
    @Autowired
    private SysBaseFuncRepository funcRepository;
    @Autowired
    private SysBaseFuncMapper funcMapper;

    @Override
    public SysBaseMenu toEntity(SysBaseMenuDTO menuDTO) {
        return menuMapper.toEntity(menuDTO);
    }

    @Override
    public SysBaseMenuDTO toDTO(SysBaseMenu sysBaseMenu) {
        return menuMapper.toDTO(sysBaseMenu);
    }

    @Override
    public List<SysBaseMenu> toEntity(List<SysBaseMenuDTO> sysBaseMenuDTOS) {
        return menuMapper.toEntity(sysBaseMenuDTOS);
    }

    @Override
    public List<SysBaseMenuDTO> toDTO(List<SysBaseMenu> sysBaseMenus) {
        return menuMapper.toDTO(sysBaseMenus);
    }

    public SysBaseMenuDTO getFuncs(SysBaseMenuDTO menuDTO){
        List<SysBaseFunc> funcList = funcRepository.findAllByMenuId(menuDTO.getId());
        if(funcList!=null && !funcList.isEmpty()){
            menuDTO.setFuncList(funcMapper.toDTO(funcList));
        }
        return menuDTO;
    }
}
